#include <iostream>
#include <string>
using namespace std;

string s;

int func()
{
    int ret = -1;
    for (int i = 1; i <= s.size(); i++)
    {
        if (s[i] == s[i - 1])
        {
            return 2;
        }
        else if (i >= 2 && s[i] == s[i - 2])
        {
            ret = 3;
        }
    }
    return ret;
}

int main()
{
    cin >> s;

    cout << func() << endl;

    return 0;
}